package com.xpgk.mvc.statistic.customerForProductList;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.xpgk.mvc.base.BaseController;
import com.xpgk.mvc.organization.Organization;
import com.xpgk.mvc.scallVisit.ScallVisitXLS;

public class CustomerForProductListController extends BaseController {
	CustomerForProductListService customerForProductListService;
	public void index(){
		setAttr("curOrgan",Organization.dao.findById(getCUserOrganIds()));
		render("customerForProductList.html");
	}
	/*
	 * 产品类型数据查询
	 */
	public void queryproductdata(){
		String sqlMy = getSqlMy(CustomerForProductListSQL.customerforproductlist_producttype);
		List<Record> list = Db.find(sqlMy);
		List<Record> result = new ArrayList<Record>();
		for(Record f : list){
			result.add(new Record().set("typeids",f.getStr("ids")).set("chanplx", f.getStr("name")));
		}
		renderJson(result);
	}
	/*
	 * 顾客数据查询
	 */
	public void customerDataQuery() throws Exception{
		String organIdsEmployee = getPara("organIdsEmployee");
		String arrivedMinDate = getPara("arrivedMinDate");
		List<Record> result = customerForProductListService.customerDataQuery(organIdsEmployee, arrivedMinDate);
		renderJson(result);
	}
	/*
	 * 顾客数据Excel导出
	 */
	public void excel() throws Exception{
		String sqlMy = getSqlMy(CustomerForProductListSQL.customerforproductlist_producttype);
		List<Record> list = Db.find(sqlMy);
		List<Record> typelist = new ArrayList<Record>();
		for(Record f : list){
			typelist.add(new Record().set("typeids",f.getStr("ids")).set("chanplx", f.getStr("name")));
		}
		String organIdsEmployee = getPara("organIdsEmployee");
		String arrivedMinDate = getPara("arrivedMinDate");
		Organization organ = Organization.dao.findById(organIdsEmployee);//门店
		String search_organIdsEmployee =organ.getStr(Organization.column_name).equals("")?"":("店面名称："+organ.getStr(Organization.column_name)+"，");
		String search = search_organIdsEmployee+"日期："+arrivedMinDate;
		List<Record> result = customerForProductListService.customerDataQuery(organIdsEmployee, arrivedMinDate);
		render(new CustomerForProductListXLS(typelist,result, "顾客购销存排名表",search));
	}
}
